package com.my.hp_hr.contorller.liuhao_controller;

import com.my.hp_hr.entity.liuhao_entity.Employee;
import com.my.hp_hr.service.liuhao_service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class EmployeeLoginServlet extends HttpServlet {
    public EmployeeService employeeService=new EmployeeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String employeeNumber = req.getParameter("employeeNumber");//用户名
            String password = req.getParameter("password");//密码
            Employee employee = employeeService.checkEmployeeByNumAndPassword(employeeNumber, password);
            req.getSession().setAttribute("employee_isLogin",employee);

            if (employee!=null&&employee.getId()!=0){
                req.getRequestDispatcher("home.jsp").forward(req,resp);
            }else {
                req.getRequestDispatcher("login.jsp").forward(req,resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
